import { Component, EventEmitter, Input, Output } from '@angular/core';

@Component({
    selector: 'app-voter',
    template: `
    <h4>{{name}}</h4>
    <button (click)="vote(true)"  [disabled]="didVote">Agree</button>
    <button (click)="vote(false)" [disabled]="didVote">Disagree</button>
  `
})
export class VoterComponent {
    @Input() name: string;
    @Output() voted = new EventEmitter<boolean>();
    didVote = false;
    var1 = '父组件与子组件通过本地变量互动';
    var2 = '父组件与子组件通过ViewChild互动';

    vote(agreed: boolean) {
        this.voted.emit(agreed);
        this.didVote = true;
    }
}